
package view;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.MultipleGradientPaint;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;

public class SpotLight {
    
    private double lastx;
    private double lasty;
    private boolean enabled = false;

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    
    public void draw(Graphics2D g2) {
        if (enabled) {
        // highlight
        Rectangle gradientBounds = new Rectangle((int) lastx, (int) lasty, 300, 200);
        double gw = gradientBounds.getWidth();
        double gh = gradientBounds.getHeight();
        double cx = gradientBounds.getCenterX();
        double cy = gradientBounds.getCenterY();
        Point2D center = new Point2D.Double(cx, cy);

        AffineTransform gradientTransform = new AffineTransform();
        gradientTransform.translate(cx, cy);
        gradientTransform.scale(gw / 2, gh / 2);
        gradientTransform.translate(-cx, -cy);

        Color transparent = new Color(1f, 1f, 1f, .0f);
        Color transparent2 = new Color(1f, 1f, 1f, .4f);
        Color transparent3 = new Color(1f,1f, 1f, .4f);

        float[] dist = {0.0f, 0.1f, 0.5f};
        Color[] colors = {transparent3, transparent2, transparent};
        MultipleGradientPaint.CycleMethod cycleMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;

        float radius = 2.0f;
        
        RadialGradientPaint gp =
                new RadialGradientPaint(center, radius, center,
                dist, colors,
                cycleMethod,
                MultipleGradientPaint.ColorSpaceType.SRGB,
                gradientTransform);

        g2.setPaint(gp);
        g2.fillOval((int) lastx, (int) lasty, 300, 200);
        }
    }

    public void setPosition(double x, double y) {                                   
        lastx = x - 130;
        lasty = y;
    }                                  
          
} // class

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
